# 模拟自动取款机
#
# 初始化变量
MONEY = 10000
USERLIST = [
	{'username':'davidjin','password':'12345'},
	{'username':'1197','password':'jzhw'},
	{'username':'1','password':'1'}
]
# 自定义查询余额方法
def getMoney(MONEY):
	print("$"*10,"余额为:{}元".format(MONEY),"$"*10)

# 自定义取钱方法
def drawMoney(money):
	global MONEY
	print("$"*10,"取走:{}元".format(money),"$"*10)
	MONEY-=money
	getMoney(MONEY)

# 自定义存钱方法
def depositMoney(money):
	global MONEY
	print("$"*10,"存入{}元".format(money),"$"*10)
	MONEY+=money
	getMoney(MONEY)

while True:
	# 登录界面
	username = input("请输入用户名:")
	password = input("请输入密码:")
	user = {}
	user['username'] = username
	user['password'] = password
	# 判断是否登录成功
	if user not in USERLIST:
		print("*"*10,"登录失败，请重新登录！","*"*10)
		continue
	print("*"*10,"登录成功！","*"*10)
	while True:
		# 初始化自动取款机主界面
		print("="*20,"自动取款机","="*20)
		print("{0:1} {1:16} {2:16}".format(" ","1.查询余额","2.取钱"))
		print("{0:1} {1:16} {2:16}".format(" ","3.存钱","4.退出"))
		# 根据键盘值进行处理
		choice = input("请输入选择：")
		# 确认输入是否有效
		while choice not in ['1','2','3','4']:
			print("无效输入，请重新选择!")
			choice = input("请输入选择：")
		if choice == '1':
			getMoney(MONEY) # 输出余额
			input("按回车键继续...")
		elif choice == '2':
			print("*"*10,"仅可取出100元纸币","*"*10)
			while True:
				num = input("请输入要取出的纸币张数:")
				# 判断所取钱数是否符合实际
				if int(num) >= 0 and int(num)*100 <= MONEY:
					break
				print("*"*10,"输入不合法，请重新输入！","*"*10)
			drawMoney(int(num)*100) # 取出钱来
			input("按回车键继续...")
		elif choice == '3':
			print("*"*6,"仅可存入100元纸币，一次性最多存入100张","*"*6)
			while True:
				num = input("请输入要存入的纸币张数:")
				# 判断所存钱数是否符合实际
				if int(num) >= 0 and int(num) <= 100:
					break
				print("*"*10,"输入不合法，请重新输入！","*"*10)
			depositMoney(int(num)*100) # 存钱
			input("按回车键继续...")
		elif choice == '4':
			print("="*15,"退出自动存取系统ing...","="*15)
			break
	break